﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace C4F.DevKit.Speech.Controls
{
    [ToolboxItem(true), ToolboxBitmap(typeof(SpeechDictation))]
    /// <summary>
    /// A control used to convert speech to text.
    /// </summary>
    public partial class SpeechDictation : UserControl
    {
        #region Private Data

        private SapiManager _sapiManager = null;

        private const string DESIGNER_CATEGORY = "Speech";

        #endregion Private Data

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the SpeechDictation control.
        /// </summary>
        public SpeechDictation()
        {
            InitializeComponent();
        }

        #endregion Constructor

        #region Properties

        /// <summary>
        /// The SAPI Manager to be used by this control.
        /// </summary>
        [Browsable(true), Category(DESIGNER_CATEGORY)]
        public SapiManager SapiManager
        {
            get { return _sapiManager; }
            set
            {                
                _sapiManager = value;

                if (!this.DesignMode && _sapiManager != null)
                    _sapiManager.SpeechRecognized += new SapiManager.SapiSpeechRecognizedEventHandler(sapi_SpeechRecognized);
            }
        }

        #endregion Properties

        #region Event Handlers

        private void btnClear_Click(object sender, EventArgs e)
        {
            OnClear();
        }

        #endregion Event Handlers

        #region Private

        private void OnClear()
        {
            textBoxDictation.Text = string.Empty;
        }

        private void sapi_SpeechRecognized(string text)
        {
            textBoxDictation.Text += text;
        }

        
        #endregion Private
    }
}